﻿using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using KinonekoSoftware.Foundation;
using KinonekoSoftware.Foundation.UI;
using KinonekoSoftware.UI;

namespace KinonekoSoftware.Studio
{
    public partial class TracerWindow : Window
    {
        
        public TracerWindow()
        {
            InitializeComponent();
            Loaded      += OnLoaded;
            Unloaded    += OnUnloaded;
        }


        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            Xplat.SetLogBroadcaster(OnTracing);
        }
        
        private void OnTracing(string obj)
        {
            Xplat.RunOnUIThread(() =>
            {
                DebugOutput?.Items.Add(new ListBoxItem { Content = obj });
            });
        }

        private void OnUnloaded(object sender, RoutedEventArgs e)
        {
            Xplat.SetLogBroadcaster(null);
        }
    }
}